/*
 * Copyright @ 2015 Goldpac Co. Ltd. All right reserved.
 * @fileName SmartCardController.java
 * @author rui.kang
 */
package com.goldpac.jssb.controller;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.alibaba.fastjson.JSON;
import com.goldpac.jssb.common.Constants;
import com.goldpac.jssb.common.Notification;
import com.goldpac.jssb.common.Pager;
import com.goldpac.jssb.common.PagerHelper;
import com.goldpac.jssb.common.Parameter;
import com.goldpac.jssb.common.SocketHelper;
import com.goldpac.jssb.model.base.Branch;
import com.goldpac.jssb.model.base.CardType;
import com.goldpac.jssb.model.base.Param;
import com.goldpac.jssb.model.base.PersoRecord;
import com.goldpac.jssb.model.base.User;
import com.goldpac.jssb.model.command.*;
import com.goldpac.jssb.pojo.vo.sical.*;
import com.goldpac.jssb.service.base.IBranchService;
import com.goldpac.jssb.service.base.ICardTypeService;
import com.goldpac.jssb.service.base.IParamService;
import com.goldpac.jssb.service.base.IPayService;
import com.goldpac.jssb.service.base.IPersoRecordLogService;
import com.goldpac.jssb.service.base.IPersoRecordService;
import com.goldpac.jssb.service.base.ISocialService;
import com.goldpac.jssb.service.base.IUserService;
import com.goldpac.jssb.socket.entity.CommonRequest;
import com.goldpac.jssb.socket.entity.CommonResponse;
import com.goldpac.jssb.socket.entity.FieldBean;
import com.goldpac.jssb.socket.entity.GetICDataResponse;
import com.goldpac.jssb.socket.entity.InputBean;
import com.goldpac.jssb.socket.entity.SocketPacket;
import com.goldpac.jssb.socket.entity.SubmitSmartCardRequest;
import com.goldpac.jssb.utils.Base64Utils;
import com.goldpac.jssb.utils.SocketPacketUtil;
import com.goldpac.jssb.utils.ValidateUtil;
import com.goldpac.jssb.utils.XmlUtils;
import com.goldpac.vtm.core.exception.RestServiceException;

/**
 * 金融卡Controller类
 * 
 * @ClassName: SmartCardController
 * @author rui.kang
 * @version 1.0<br />
 * @Date 2017年5月15日 上午10:07:39<br />
 * @Logs <br />
 *       ****************************************************<br />
 */
@Controller
public class SmartCardController extends BaseController {
    @Autowired
    private IParamService          paramService;
    @Autowired
    private IPersoRecordService    persoRecordService;
    @Autowired
    private IPersoRecordLogService persoRecordLogService;
    @Autowired
    private ICardTypeService       cardTypeService;
    @Autowired
    private IBranchService         branchService;
    @Autowired
    private IUserService           userService;
    @Autowired
    private ISocialService         socialService;
    @Autowired
    private IPayService            payService;

    @RequestMapping("scard/tkhhk")
    public void TKHHK(Model model, HttpServletRequest request) {
        // List<CardType> list = cardTypeService.findByTypeId(Constants.CARD_TYPE_JRK);
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CardType.class);
//        String qlstr = "from CardType where cardFormatId=:p1 or cardFormatId=:p2 ";
//        Parameter parameter = new Parameter(Constants.CARD_TYPE_JRK, Constants.CARD_TYPE_UNION);
//        List<CardType> list = cardTypeService.find(qlstr, parameter);
        detachedCriteria.add(Restrictions.eq("status", 0));
        List<CardType> list2 = cardTypeService.getList(detachedCriteria);
        if (list2 == null) {
            list2 = new ArrayList<CardType>();
        }
        model.addAttribute("cList", list2);
    }
    
    @RequestMapping("scard/sbtkhhk")
    public void SBTKHHK(Model model, HttpServletRequest request) {
    }
    
    @RequestMapping("scard/faceDetect")
    public void faceDetect(Model model, HttpServletRequest request) {
    }
    
    @RequestMapping("scard/sbtkhhkConfirm")
    public void sbtkhhkConfirm(Model model, HttpServletRequest request) {
    }

    @RequestMapping(value = "scard/getPersoInfo", method = RequestMethod.POST)
    @ResponseBody
    public Object getPersoInfo(final Model model, final HttpServletRequest request, HttpServletResponse response) throws IOException {
        Notification notification = new Notification();
        // String cardpr = "040018";
        String idtfType = request.getParameter("idtfType");
        String cardpr = request.getParameter("cardpr");
        String idtfno = request.getParameter("idtfno").trim();
        String custna = request.getParameter("custna").trim();
        String jrno = request.getParameter("jrno").trim();
        String endjrno = request.getParameter("endjrno").trim();
        String branchCode = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH);
        String userName = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_NAME);
        User u = userService.get("username", userName);
        String teller = u.getTeller();
        Param param = paramService.get("PKey", Constants.KEY_II_SERVER_IP);
        String ip = param.getPValue();
        param = paramService.get("PKey", Constants.KEY_II_SERVER_PORT);
        String port = param.getPValue();


        if (StringUtils.isBlank(idtfType)){
            notification.setSuccess(false);
            notification.setTipMessage("证件种类为空。");
            return notification;
        }
        if (StringUtils.isBlank(cardpr)){
            notification.setSuccess(false);
            notification.setTipMessage("卡款名称为空。");
            return notification;
        }
        if (StringUtils.isBlank(idtfno)){
            notification.setSuccess(false);
            notification.setTipMessage("证件号码为空。");
            return notification;
        }
        if (StringUtils.isBlank(custna)){
            notification.setSuccess(false);
            notification.setTipMessage("客户姓名为空。");
            return notification;
        }
        if (StringUtils.isBlank(jrno)){
            notification.setSuccess(false);
            notification.setTipMessage("起始卡号为空。");
            return notification;
        }
        if (StringUtils.isBlank(endjrno)){
            notification.setSuccess(false);
            notification.setTipMessage("终止卡号为空。");
            return notification;
        }

        SocketHelper socket = null;

        try {
            socket = new SocketHelper(ip, Integer.valueOf(port));
            boolean flag = socket.createSocket();
            if (flag) {
                CommonRequest req = new CommonRequest();
                req.setPrcscd("GetICData");
                List<FieldBean> list = new ArrayList<FieldBean>();
                list.add(new FieldBean("IDTFTP", idtfType));
                list.add(new FieldBean("IDTFNO", idtfno));
                list.add(new FieldBean("branchCode", branchCode + "," + teller));// 将网点机构号和柜员号一起传到服务端，用于0017请求数据报文
                list.add(new FieldBean("CUSTNA", custna));
                list.add(new FieldBean("CARDPR", cardpr));
                list.add(new FieldBean("JRNO", jrno));
                list.add(new FieldBean("ENDJRNO", endjrno));
                InputBean input = new InputBean(list);
                req.setInput(XmlUtils.buildNodeContent(input));
                SocketPacket packet = SocketPacketUtil.createSocketPacket(req.buildXmlContent());
                String responseData = socket.sendMessage(packet.toString());
                if (StringUtils.isNotEmpty(responseData)) {
                    GetICDataResponse resp = new GetICDataResponse(responseData);
                    if (StringUtils.isNotEmpty(resp.getErorcd())) {
                        notification.setSuccess(false);
                        notification.setTipMessage(resp.getErortx());
                    } else {
                        System.out.println(Base64Utils.getDecryptString(resp.getOriginalJson()));
                        notification.setTipMessage(Base64Utils.getDecryptString(resp.getOriginalJson()));
                    }
                } else {
                    notification.setSuccess(false);
                    notification.setTipMessage("获取数据超时。");
                }

            } else {
                notification.setSuccess(false);
                notification.setTipMessage("与即时发卡服务连接失败  :");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("与即时发卡服务连接失败  :" + ex.getMessage());
        }finally {
                socket.closeSocket();
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/getMakeCardInfo", method = RequestMethod.POST)
    @ResponseBody
    public Object getMakeCardInfo(HttpServletRequest request, @RequestBody GetMakeCardInfoCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.getMakeCardInfoValidate(command, notification) == -1) {
            return notification;
        }
        
        String userName = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_NAME);
        User user = userService.get("username", userName);
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        //银行制卡进度查询
        try {
            GetMakeCardInfoRp getMakeCardInfoRp = socialService.getMakeCardInfo(command);
            if(getMakeCardInfoRp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("查询银行卡号失败【" + getMakeCardInfoRp.getMessage() + "】");
                return notification;
            } else {
                command.setBankNo(getMakeCardInfoRp.getBankNo());
                command.setSbNumber(getMakeCardInfoRp.getSbNumber());
            }
        } catch (Exception ex) {
            notification.setSuccess(false);
            notification.setTipMessage("查询银行卡号失败【" + ex.getMessage() + "】");
            return notification;
        }
        
        //卡状态查询
        GetCardCommand getCardCommand = new GetCardCommand();
        getCardCommand.setAab301(user.getCityCode());
        getCardCommand.setAac002(command.getIdNumber());
        getCardCommand.setAac003(command.getName());
        getCardCommand.setAaz500(command.getSbNumber());
        try {
            BaseRp rp = socialService.getCard(getCardCommand);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("查询银行卡号失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                String message = rp.getMessage();
                if("正式挂失".equals(message) || "OK".equals(message) || "临时挂失".equals(message)) {
                    command.setStatus(message);
                } else {
                    notification.setSuccess(false);
                    notification.setTipMessage("卡状态查询失败【" + rp.getMessage() + "】");
                    return notification;
                }
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("查询银行卡号失败【" + e.getMessage() + "】");
            return notification;
        }
        
        //人员数据查询
        GetRysjCommand getRysjCommand = new GetRysjCommand();
        getRysjCommand.setAab301(user.getCityCode());
        getRysjCommand.setAac002(command.getIdNumber());
        getRysjCommand.setAac003(command.getName());
        try {
            GetRysjRp getRysjRp = socialService.getRysj(getRysjCommand);
            if(getRysjRp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("查询银行卡号失败【" + getRysjRp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(command));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("查询银行卡号失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/applyCard", method = RequestMethod.POST)
    @ResponseBody
    public Object applyCard(HttpServletRequest request, @RequestBody ApplyCardCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.applyCardValidate(command, notification) == -1) {
            return notification;
        }
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setAab301(user.getCityCode());
        command.setCounty(user.getCounty());
        command.setDevNo(user.getDevNo());
        command.setDevPer(user.getDevPer());
        
        try {
            BaseRp rp = socialService.applyCard(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardPostil", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardPostil(HttpServletRequest request, @RequestBody MakeCardPostilCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardPostilValidate(command, notification) == -1) {
            return notification;
        }
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setAab301(user.getCityCode());
        
        try {
            BaseRp rp = socialService.makeCardPostil(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardPeoNum", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardPeoNum(HttpServletRequest request, @RequestBody MakeCardPeoNumCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardPeoNumValidate(command, notification) == -1) {
            return notification;
        }
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setCityCode(user.getCityCode());
        command.setCounty(user.getCounty());
        command.setOrganization(user.getCounty());
        
        try {
            MakeCardPeoNumRp rp = socialService.makeCardPeoNum(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardPeo", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardPeo(HttpServletRequest request, @RequestBody MakeCardPeoCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardPeoValidate(command, notification) == -1) {
            return notification;
        }
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setCityCode(user.getCityCode());
        command.setCounty(user.getCounty());
        command.setOrganization(user.getCounty());
        
        try {
            MakeCardPeoRp rp = socialService.makeCardPeo(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/getBatchNum", method = RequestMethod.POST)
    @ResponseBody
    public Object getBatchNum(HttpServletRequest request, @RequestBody GetBatchNumCommand command) throws IOException {
        Notification notification = new Notification();
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }

        command.setCounty(user.getCounty());
        
        try {
            GetBatchNumRp rp = socialService.getBatchNum(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardBatch", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardBatch(HttpServletRequest request, @RequestBody MakeCardBatchCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardBatchValidate(command, notification) == -1) {
            return notification;
        }
      
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setCityCode(user.getCityCode());
        command.setCounty(user.getCounty());
        
        try {
            MakeCardBatchRp rp = socialService.makeCardBatch(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardData", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardData(HttpServletRequest request, @RequestBody MakeCardDataCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardDataValidate(command, notification) == -1) {
            return notification;
        }
        
        try {
            MakeCardDataRp rp = socialService.makeCardData(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("申请失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("申请失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/makeCardCallBack", method = RequestMethod.POST)
    @ResponseBody
    public Object makeCardCallBack(HttpServletRequest request, @RequestBody MakeCardCallBackCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.makeCardCallBackValidate(command, notification) == -1) {
            return notification;
        }
        
        try {
            MakeCardCallBackRp rp = socialService.makeCardCallBack(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("社保卡回盘失败【" + rp.getMessage() + "】");
                return notification;
            } else {
                notification.setTipMessage(JSON.toJSONString(rp));
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("社保卡回盘失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/cardAtivate", method = RequestMethod.POST)
    @ResponseBody
    public Object cardAtivate(HttpServletRequest request, @RequestBody CardAtivateCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.cardAtivateValidate(command, notification) == -1) {
            return notification;
        }
        
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setCityCode(user.getCityCode());
        
        try {
            BaseRp rp = socialService.cardAtivate(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("领卡启用失败【" + rp.getMessage() + "】");
                return notification;
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("领卡启用失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/authYWMC", method = RequestMethod.POST)
    @ResponseBody
    public Object authYWMC(HttpServletRequest request, @RequestBody YWMCCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.authYWMCValidate(command, notification) == -1) {
            return notification;
        }
        
        try {
            BaseRp rp = socialService.authYWMC(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("人脸认证失败【" + rp.getMessage() + "】");
                return notification;
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("人脸认证失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/lossCard", method = RequestMethod.POST)
    @ResponseBody
    public Object lossCard(HttpServletRequest request, @RequestBody LossCardCommand command) throws IOException {
        Notification notification = new Notification();
        if (ValidateUtil.lossCardValidate(command, notification) == -1) {
            return notification;
        }
        
        User user = userService.getCurrentUser();
        if (ValidateUtil.userValidate(user, notification) == -1) {
            return notification;
        }
        
        command.setCityCode(user.getCityCode());
        
        try {
            BaseRp rp = socialService.lossCard(command);
            if(rp.getCode() == 1) {
                notification.setSuccess(false);
                notification.setTipMessage("正式挂失失败【" + rp.getMessage() + "】");
                return notification;
            }
        } catch (RestServiceException e) {
            // TODO Auto-generated catch block
            notification.setSuccess(false);
            notification.setTipMessage("正式挂失失败【" + e.getMessage() + "】");
        }
        return notification;
    }
    
    @RequestMapping(value = "scard/notifyPersoResult", method = RequestMethod.POST)
    @ResponseBody
    public Object notifyPersoResult(final Model model, final HttpServletRequest request, HttpServletResponse response){
        Notification notification = new Notification();
        String prId = request.getParameter("prId");
//        String prId = request.getParameter("prId");
        String code = request.getParameter("code");
        String message  = request.getParameter("message");
        String atr  = request.getParameter("atr");
        Param param = paramService.get("PKey", Constants.KEY_II_SERVER_IP);
        String ip = param.getPValue();
        param = paramService.get("PKey", Constants.KEY_II_SERVER_PORT);
        String port = param.getPValue();
        SocketHelper socket = null;
        try {
            socket = new SocketHelper(ip, Integer.valueOf(port));
            boolean flag = socket.createSocket();
            if (flag) {
                CardDataCommand cardData = new CardDataCommand();
                cardData.setPersoRecordId(Integer.valueOf(prId));
                cardData.setFlag(code);
                cardData.setErrormsg(message);
                cardData.setAtr(atr);
                cardData.setCardTypeCode("jrk");
                CommonRequest req = new CommonRequest();
                req.setPrcscd("NotifyPersoResult");
                List<FieldBean> list = new ArrayList<FieldBean>();
                list.add(new FieldBean("code", cardData.getFlag()));
                list.add(new FieldBean("message", cardData.getErrormsg()));
                String json = JSON.toJSONString(cardData);
                json = Base64Utils.getEncryptString(json);
                list.add(new FieldBean("originalJson",json));
                InputBean input = new InputBean(list);
                req.setInput(XmlUtils.buildNodeContent(input));
                SocketPacket packet = SocketPacketUtil.createSocketPacket(req.buildXmlContent());
                String responseData = socket.sendMessage(packet.toString());
                if (StringUtils.isNotEmpty(responseData)) {
                    GetICDataResponse resp = new GetICDataResponse(responseData);
                    if (StringUtils.isNotEmpty(resp.getErorcd())) {
                        notification.setSuccess(false);
                        notification.setTipMessage(resp.getErortx());
                    } else {
                        System.out.println(resp.getOriginalJson());
                        notification.setTipMessage(resp.getOriginalJson());
                    }
                } else {
                    notification.setSuccess(false);
                    notification.setTipMessage("提交制卡结果失败，请检查。");
                }
            } else {
                notification.setSuccess(false);
                notification.setTipMessage("与即时发卡服务连接失败  :");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("与即时发卡服务连接失败  :" + ex.getMessage());
        }finally {
            socket.closeSocket();
        }
        
        return notification;
    }
    
    // 新版 应缴信息同步V2
    @RequestMapping(value = "pay/newSyncInfoV2", method = RequestMethod.POST)
    @ResponseBody
    public BaseRp newSyncInfoV2(HttpServletRequest request, @RequestBody SyncInfoCommand command)
            throws RestServiceException {
        BaseRp rp = payService.newSyncInfoV2(command);
        return rp;
    }
    
    // 支付结果查询接口
    @RequestMapping(value = "pay/payQueryResult", method = RequestMethod.POST)
    @ResponseBody
    public BaseRp payQueryResult(HttpServletRequest request, @RequestBody SyncInfoCommand command)
            throws RestServiceException {
        BaseRp rp = payService.payQueryResult(command);
        return rp;
    }
    
    @RequestMapping(value = "scard/getSmartCardDetial", method = RequestMethod.POST)
    @ResponseBody
    public Object getSmartCardDetial(final Model model, final HttpServletRequest request, HttpServletResponse response){
        Notification notification = new Notification();
        String uId = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_NAME);
        String prId = request.getParameter("prId");
        Param param = paramService.get("PKey", Constants.KEY_II_SERVER_IP);
        String ip = param.getPValue();
        param = paramService.get("PKey", Constants.KEY_II_SERVER_PORT);
        String port = param.getPValue();
        SocketHelper socket = null;
        try {
            socket = new SocketHelper(ip, Integer.valueOf(port));
            boolean flag = socket.createSocket();
            if (flag) {
                CommonRequest req = new CommonRequest();
                req.setPrcscd("GetSmartCard");
                List<FieldBean> list = new ArrayList<FieldBean>();
                list.add(new FieldBean("prId", prId));
                list.add(new FieldBean("IDTFNO", ""));
                list.add(new FieldBean("operator",  uId));
                InputBean input = new InputBean(list);
                req.setInput(XmlUtils.buildNodeContent(input));
                SocketPacket packet = SocketPacketUtil.createSocketPacket(req.buildXmlContent());
                String responseData = socket.sendMessage(packet.toString());
                if (StringUtils.isNotEmpty(responseData)) {
                    GetICDataResponse resp = new GetICDataResponse(responseData);
                    if (StringUtils.isNotEmpty(resp.getErorcd())) {
                        notification.setSuccess(false);
                        notification.setTipMessage(resp.getErortx());
                    } else {
//                        System.out.println(Base64Utils.getDecryptString(resp.getOriginalJson()));
                        notification.setTipMessage(Base64Utils.getDecryptString(resp.getOriginalJson()));
                    }
                } else {
                    notification.setSuccess(false);
                    notification.setTipMessage("获取数据超时。");
                }
            } else {
                notification.setSuccess(false);
                notification.setTipMessage("与即时发卡服务连接失败  :");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("与即时发卡服务连接失败  :" + ex.getMessage());
        }finally {
            socket.closeSocket();
        }
        return notification;
    }
    

    @RequestMapping(value = "scard/submitIssue", method = RequestMethod.POST)
    @ResponseBody
    public Object submitIssue(final Model model, final HttpServletRequest request, HttpServletResponse response) {
        Notification notification = new Notification();
        // String idtftp = request.getParameter("idtftp");
        String idtfno = "";// request.getParameter("idtfno");
        String cardno = request.getParameter("cardNo");
        if (cardno == null) {
            cardno = "";
        }
        String prId = request.getParameter("prId");
        String uId = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_NAME);
        // String branchCode = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH);
        Param param = paramService.get("PKey", "key_ii_server_ip_1");
        String ip = param.getPValue();
        param = paramService.get("PKey", "key_ii_server_port_1");
        String port = param.getPValue();
        param = paramService.get("PKey", "key_ii_server_ip_2");
        String ipBak = param.getPValue();
        param = paramService.get("PKey", "key_ii_server_port_2");
        String portBak = param.getPValue();
        SocketHelper socket = null;
        try {
            socket = new SocketHelper(ip, Integer.valueOf(port));
            boolean flag = socket.createSocket();
            int ipAndPort = 1;
            // 如果服务器1关闭，建立与服务器2的连接
            if (!flag) {
                socket = new SocketHelper(ipBak, Integer.valueOf(portBak));
                flag = socket.createSocket();
                ipAndPort = 2;
            }
            // 如果服务器2连接失败，返回与即时发卡服务连接失败错误信息
            if (!flag) {
                notification.setSuccess(false);
                notification.setTipMessage("提交制卡请求失败，与即时发卡服务连接失败  .");
                return notification;
            }
            SubmitSmartCardRequest req = new SubmitSmartCardRequest(idtfno, cardno, prId);
            req.setOperator(uId);
            SocketPacket packet = SocketPacketUtil.createSocketPacket(req.toString());
            String responseData = socket.sendMessage(packet.toString());
//            System.out.println(responseData);
            // 第一次发送提交制卡请求，获取服务器返回信息
            // 如果返回信息为空,提示与即时发卡服务连接失败错误信息
            if (StringUtils.isBlank(responseData)) {
                notification.setSuccess(false);
                notification.setTipMessage("提交制卡请求失败，请求服务器超时。");
                return notification;
            }
            CommonResponse resp = new CommonResponse(responseData);
            // 如果返回信息中交易码为空，表示服务已下发数据到客户端，
            if (StringUtils.isBlank(resp.getErorcd())) {
                notification.setTipMessage(Base64Utils.getDecryptString(resp.getOriginalJson()));
                notification.setSuccess(true);
                return notification;
            }
            // 如果返回提示信息包含‘客户端已关闭’，则建立与服务器2的连接，重新发送提交制卡请求报文
            if (resp.getErortx().contains("客户端已关闭")) {
                // 如果当前Socket是服务器2的连接，直接返回。
                if (ipAndPort == 2) {
                    notification.setSuccess(false);
                    notification.setTipMessage(resp.getErortx());
                    return notification;
                }
                socket.closeSocket();
                socket = new SocketHelper(ipBak, Integer.valueOf(portBak));
                flag = socket.createSocket();
                // 如果服务器2已关闭，直接返回提示信息
                if (!flag) {
                    notification.setSuccess(false);
                    notification.setTipMessage(resp.getErortx());
                    return notification;
                }
                // 向服务器2发送提求制卡报文
                responseData = socket.sendMessage(packet.toString());
                if (StringUtils.isBlank(responseData)) {
                    notification.setSuccess(false);
                    notification.setTipMessage("提交制卡请求失败，请求服务器超时。");
                    return notification;
                }
                resp = new CommonResponse(responseData);
                if (StringUtils.isBlank(resp.getErorcd())) {
                    notification.setTipMessage(Base64Utils.getDecryptString(resp.getOriginalJson()));
                    notification.setSuccess(true);
                    return notification;
                }else{
                    notification.setSuccess(false);
                    notification.setTipMessage(resp.getErortx());
                }
            } else {
                notification.setSuccess(false);
                notification.setTipMessage(resp.getErortx());
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("与即时发卡服务连接失败  :" + ex.getMessage());
        } finally {
            if (socket != null) {
                socket.closeSocket();
            }
        }
        return notification;
    }
    
    
    public boolean checkResponseData(String responseData , Notification notification){
        
        return true;
    }

    @RequestMapping(value = "scard/getPersoList", method = RequestMethod.POST)
    @ResponseBody
    public Object getMenuList(Model model, HttpServletRequest request, @ModelAttribute PersoInfoCommand command) {
        String idNumber = request.getParameter("idNumber");
        if (StringUtils.isNotEmpty(idNumber)) {
            command.setIdNumber(idNumber);
        }
        // 获取请请中分页信息
        Pager pager = PagerHelper.createPager(request);
        pager = persoRecordService.findByPager(pager, command);
        Map<String, Object> maprow = new HashMap<String, Object>();
        maprow.put("Rows", pager.getResultList());
        maprow.put("Total", pager.getTotalCount());
        return maprow;
    }

    /**
     * list 页面
     * 
     * @Title: list
     * @param model
     * @param request
     */
    @RequestMapping("scard/result")
    public void result(final Model model, HttpServletRequest request) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CardType.class);
        // String qlstr = "from CardType where cardFormatId=:p1 or cardFormatId=:p2 ";
        // Parameter parameter = new Parameter(Constants.CARD_TYPE_JRK, Constants.CARD_TYPE_UNION);
        // List<CardType> list = cardTypeService.find(qlstr, parameter);
        detachedCriteria.add(Restrictions.eq("status", 0));
        List<CardType> list2 = cardTypeService.getList(detachedCriteria);
        if (list2 == null) {
            list2 = new ArrayList<CardType>();
        }
        model.addAttribute("cList", list2);
    }

    /**
     * list 页面
     * 
     * @Title: list
     * @param model
     * @param request
     */
    @RequestMapping("scard/list")
    public void list(final Model model, HttpServletRequest request) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CardType.class);
        // String qlstr = "from CardType where cardFormatId=:p1 or cardFormatId=:p2 ";
        // Parameter parameter = new Parameter(Constants.CARD_TYPE_JRK, Constants.CARD_TYPE_UNION);
        // List<CardType> list = cardTypeService.find(qlstr, parameter);
        detachedCriteria.add(Restrictions.eq("status", 0));
        List<CardType> list2 = cardTypeService.getList(detachedCriteria);
        if (list2 == null) {
            list2 = new ArrayList<CardType>();
        }
        model.addAttribute("cList", list2);
    }

    /**
     * ajax请求
     * 
     * @Title: getPersoInfoList
     * @param model
     * @param request
     * @param persoInfoCommand
     * @return object
     */
    @RequestMapping(value = "scard/list", method = RequestMethod.POST)
    @ResponseBody
    public Object getPersoInfoList(Model model, HttpServletRequest request, @ModelAttribute PersoInfoCommand persoInfoCommand) {
        String starDate = request.getParameter("starDate");
        String reqBranchCode = request.getParameter("reqBranchCode");
        String branchCode = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH);
        Integer branchID = (Integer) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH_ID);
        persoInfoCommand.setBranchId(branchID);
        if (StringUtils.isNotEmpty(reqBranchCode)) {
            persoInfoCommand.setReqBranchName(reqBranchCode);
        }
        Set<Integer> userIdSet = new HashSet<Integer>();
        Set<String> branchCodeSet = new HashSet<String>();
        userIdSet = branchService.listSelfAndChildId(branchID);
        for (Iterator iterator = userIdSet.iterator(); iterator.hasNext();) {
            Integer integer = (Integer) iterator.next();
            branchCodeSet.add(branchService.get(integer).getCode());
        }
        persoInfoCommand.setBranchChildBranchCodes(branchCodeSet);
        if (StringUtils.isNotEmpty(starDate)) {
            persoInfoCommand.setStarDate(starDate);
        }
        String endDate = request.getParameter("endDate");
        if (StringUtils.isNotEmpty(endDate)) {
            persoInfoCommand.setEndDate(endDate);
        }
        String ctCode = request.getParameter("cardTypeCode");
        if (StringUtils.isNotBlank(ctCode)) {
            persoInfoCommand.setCardTypeCode(ctCode);
        }
        // type 批量制卡页面还是制卡数据页面
        String type = request.getParameter("type");
        if (StringUtils.isNotBlank(type)) {
            persoInfoCommand.setRemark(type);
            persoInfoCommand.setBranchCode(branchCode);
        }
        /*
         * String holdName = request.getParameter("holdName"); if (StringUtils.isNotEmpty(holdName)) { persoInfoCommand.setHoldName(holdName); } String idNumber = request.getParameter("idNumber"); if (StringUtils.isNotEmpty(idNumber)) { persoInfoCommand.setIdNumber(idNumber); }
         */
        String cardNo = request.getParameter("cardNo");
        if (StringUtils.isNotEmpty(cardNo)) {
            persoInfoCommand.setCardNo(cardNo);
        }
        // 获取请请中分页信息
        Pager pager = PagerHelper.createPager(request);
        pager = persoRecordService.findPersoedListByPager(pager, persoInfoCommand);
        Map<String, Object> maprow = new HashMap<String, Object>();
        maprow.put("Rows", pager.getResultList());
        maprow.put("Total", pager.getTotalCount());
        return maprow;
    }

    /**
     * 制卡明细清单
     * 
     * @Title: detailList
     * @param model
     * @param request
     */
    @RequestMapping("scard/detail")
    public void detailList(Model model, HttpServletRequest request) {
        String qlstr = "from CardType where cardFormatId=:p1 or cardFormatId=:p2 ";
        Parameter parameter = new Parameter(Constants.CARD_TYPE_JRK, Constants.CARD_TYPE_UNION);
        List<CardType> list = cardTypeService.find(qlstr, parameter);
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CardType.class);
        detachedCriteria.add(Restrictions.eq("status", 0));
        List<CardType> list2 = cardTypeService.getList(detachedCriteria);
        if (list == null) {
            list = new ArrayList<CardType>();
        }
        model.addAttribute("cList", list2);
    }

    @RequestMapping(value = "scard/detailAjax", method = RequestMethod.POST)
    @ResponseBody
    public Object detailList(Model model, HttpServletRequest request, HttpServletResponse response, @ModelAttribute PersoRecordLogCommand command) {
        // 获取请请中分页信息
        Pager pager = PagerHelper.createPager(request);
        String starDate = request.getParameter("starDate");
        if (starDate != null && !"".equals(starDate.trim())) {
            command.setStarDate(starDate);
        }
        String ctCode = request.getParameter("cardTypeCode");
        if (StringUtils.isNotBlank(ctCode)) {
            command.setCardTypeCode(ctCode);
        }
        String endDate = request.getParameter("endDate");
        if (endDate != null && !"".equals(endDate.trim())) {
            command.setEndDate(endDate);
        }
        Integer branchID = (Integer) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH_ID);
        command.setBranchId(branchID);
        command.setBranchChildIds(branchService.listSelfAndChildId(branchID));
        // String branchCode = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH);
        // 获取所有用户列表数据
        pager = persoRecordLogService.findPagerAllSmartCard(pager, command);
        Map<String, Object> maprow = new HashMap<String, Object>();
        maprow.put("Rows", pager.getResultList());
        maprow.put("Total", pager.getTotalCount());
        // System.out.println(maprow);
        return maprow;
    }

    /*@RequestMapping(value = "scard/modify", method = RequestMethod.POST)
    @ResponseBody
    public Object modify(Model model, @RequestParam Integer id, HttpServletRequest request) {
        Notification notification = new Notification();
        try {
            if (id != null) {
                PersoRecord pr = persoRecordService.get(id);
                if (pr != null) {
                    // if (StringUtils.equals(pr.getPersoStatus(), "300") || StringUtils.equals(pr.getPersoStatus(), "301") || StringUtils.equals(pr.getPersoStatus(), "302")) {
                    if (StringUtils.equals(pr.getPersoStatus(), "311") || StringUtils.equals(pr.getPersoStatus(), "312") || StringUtils.equals(pr.getPersoStatus(), "310") || StringUtils.equals(pr.getPersoStatus(), "300") || StringUtils.equals(pr.getPersoStatus(), "302") || StringUtils.equals(pr.getPersoStatus(), "301")) {
                        pr.setPersoStatus(Constants.PERSO_CODE_INIT);
                        pr.setPersoStatusDesc("数据重置");
                        persoRecordService.modifyPersoRecord(pr);
                        notification.setTipMessage("数据重置成功");
                    } else {
                        notification.setTipMessage("数据不能重置");
                    }
                }
            }
        } catch (Exception ex) {
            notification.setSuccess(false);
            notification.setTipMessage(Constants.MSG_TIP_DELETE_FAIL);
        }
        return notification;
    }*/

    @RequestMapping(value = "scard/modify", method = RequestMethod.POST)
    @ResponseBody
    public Object modify(Model model, @RequestParam String id, HttpServletRequest request) {
        Notification notification = new Notification();
        try {
            if (id != null) {
                PersoRecord pr = persoRecordService.get(Integer.parseInt(id));
                if (pr != null) {
                    // if (StringUtils.equals(pr.getPersoStatus(), "300") || StringUtils.equals(pr.getPersoStatus(), "301") || StringUtils.equals(pr.getPersoStatus(), "302")) {
                    if (StringUtils.equals(pr.getPersoStatus(), Constants.PERSO_CODE_IC_SUCCESS)) {
                        pr.setPersoStatus(Constants.PERSO_CODE_INIT);
                        pr.setRemark("数据重置");
                        persoRecordService.modifyPersoRecord(pr);
                        notification.setTipMessage("数据重置成功");
                    } else {
                        notification.setTipMessage("数据不能重置");
                    }
                }
            }
        } catch (Exception ex) {
            notification.setSuccess(false);
            notification.setTipMessage(Constants.MSG_TIP_DELETE_FAIL);
        }
        return notification;
    }

    @RequestMapping(value = "scard/query", method = RequestMethod.POST)
    @ResponseBody
    public Object query(Model model, HttpServletRequest request, HttpServletResponse response) throws IOException {
        Notification notification = new Notification();
        try {
            persoRecordService.flush();
            PersoRecord pr = persoRecordService.get(Integer.valueOf(request.getParameter("prId")));
            if (pr != null) {
                if (StringUtils.equals(pr.getPersoStatus(), "301") || StringUtils.equals(pr.getPersoStatus(), "500")) {
                    notification.setSuccess(true);
                    notification.setTipMessage("制卡成功");
                    return notification;
                } else if (StringUtils.equals(pr.getPersoStatus(), "302")) {
                    notification.setSuccess(false);
                    notification.setTipMessage("制卡失败");
                    notification.setContent("制卡失败，失败详情请在【制卡明细】页面查看");
                    return notification;
                } else if (StringUtils.equals(pr.getPersoStatus(), "501")) {
                    notification.setSuccess(false);
                    notification.setTipMessage("入库调拨失败");
                    notification.setContent("制卡成功但入库调拨失败，请在【制卡结果页面】手动执行 【入库调拨】操作");
                    return notification;
                }
            }
            notification.setSuccess(false);
            notification.setTipMessage("正在制卡，请稍候....");
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("失败  :" + ex.getMessage());
        }
        return notification;
    }

    @RequestMapping(value = "scard/allot", method = RequestMethod.POST)
    @ResponseBody
    public Object allot(final Model model, final HttpServletRequest request, HttpServletResponse response) {
        Notification notification = new Notification();
        String prId = request.getParameter("id");
        String uId = (String) request.getSession().getAttribute(Constants.LOGIN_CURRENT_NAME);
        Param param = paramService.get("PKey", Constants.KEY_II_SERVER_IP);
        String ip = param.getPValue();
        param = paramService.get("PKey", Constants.KEY_II_SERVER_PORT);
        String port = param.getPValue();
        SocketHelper socket = null;
        try {
            socket = new SocketHelper(ip, Integer.valueOf(port));
            boolean flag = socket.createSocket();
            if (flag) {
                CommonRequest req = new CommonRequest();
                req.setPrcscd("SubmitAllot");
                List<FieldBean> list = new ArrayList<FieldBean>();
                list.add(new FieldBean("prId", prId));
                list.add(new FieldBean("uId", uId));
                InputBean input = new InputBean(list);
                req.setInput(XmlUtils.buildNodeContent(input));
                SocketPacket packet = SocketPacketUtil.createSocketPacket(req.buildXmlContent());
                String responseData = socket.sendMessage(packet.toString());
                // System.out.println(responseData);
                if (StringUtils.isNotEmpty(responseData)) {
                    CommonResponse resp = new CommonResponse(responseData);
                    if (StringUtils.isNotEmpty(resp.getErorcd())) {
                        notification.setSuccess(false);
                        notification.setTipMessage(resp.getErortx());
                    } else {
                        // System.out.println(Base64Utils.getDecryptString(resp.getOriginalJson()));
                        // notification.setTipMessage(Base64Utils.getDecryptString(resp.getOriginalJson()));
                        notification.setTipMessage(resp.getOriginalJson());
                    }
                } else {
                    notification.setSuccess(false);
                    notification.setTipMessage("请求超时。");
                }

            } else {
                notification.setSuccess(false);
                notification.setTipMessage("与即时发卡服务连接失败  :");
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            notification.setSuccess(false);
            notification.setTipMessage("与即时发卡服务连接失败  :" + ex.getMessage());
        }finally {
            socket.closeSocket();
        }
        return notification;
    }

    /**
     * Description:批量制卡 Date:2018年1月30日 Param:@param model Param:@param ids Param:@param request
     */
    @RequestMapping("scard/submitBatch")
    public void submitBatch(Model model, @RequestParam String ids, HttpServletRequest request) {
        if (StringUtils.isNotBlank(ids)) {
            List<PersoInfoCommand> list = persoRecordService.findListByIds(ids);
            // List<String> arr = new ArrayList<String>();
            String[] arrs = new String[list.size()];
            int index = 0;
            StringBuffer sb = new StringBuffer();
            for (PersoInfoCommand pi : list) {
                if (index > 0) {
                    sb.append(",");
                }
                sb.append(pi.getPersoRecordId().toString());
                index++;
            }
            model.addAttribute("ids", sb.toString());
            model.addAttribute("resultList", list);
        }
    }

    /**
     * 批量页面
     * 
     * @Title: list
     * @param model
     * @param request
     */
    @RequestMapping("scard/batch")
    public void batch(final Model model, HttpServletRequest request) {
        DetachedCriteria detachedCriteria = DetachedCriteria.forClass(CardType.class);
        detachedCriteria.add(Restrictions.eq("status", 0));
        List<CardType> list2 = cardTypeService.getList(detachedCriteria);
        if (list2 == null) {
            list2 = new ArrayList<CardType>();
        }
        model.addAttribute("cList", list2);
        Integer branchID = (Integer) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH_ID);
        List<Branch> branchList = branchService.listSelfAndChild(branchID);
        model.addAttribute("bList", branchList);
    }

    @RequestMapping(value = "scard/dealerror")
    @ResponseBody
    public Object dealerror(Model model, HttpServletRequest request, HttpServletResponse response,@ModelAttribute PersoRecordLogCommand command) throws IOException {

        Integer branchID = (Integer) request.getSession().getAttribute(Constants.LOGIN_CURRENT_BRANCH_ID);
        List<Branch> branchList = branchService.listSelfAndChild(branchID);
        model.addAttribute("bList", branchList);

        return model;

    }
    @RequestMapping(value = "scard/errordata")
    @ResponseBody
    public Object dealErrorData(Model model, HttpServletRequest request, HttpServletResponse response,@ModelAttribute PersoRecordLogCommand command) throws IOException {
        String cardNo=request.getParameter("cardNo");
        if (StringUtils.isNotEmpty(cardNo)) {
            command.setCardNo(cardNo);
        }
        String branchId=request.getParameter("branchId");
        if (StringUtils.isNotEmpty(branchId)) {
            command.setBranchId(Integer.parseInt(branchId));
        }
        String starDate=request.getParameter("starDate");
        if (StringUtils.isNotEmpty(starDate)) {
            command.setStarDate(starDate);
        }
        String endDate=request.getParameter("endDate");
        if (StringUtils.isNotEmpty(endDate)) {
            command.setEndDate(endDate);
        }
        Pager pager = PagerHelper.createPager(request);
        pager=persoRecordService.findPersoRecordByPager(pager,command);
        if(pager == null){
            return null;
        }

        Map<String, Object> maprow = new HashMap<String, Object>();
        maprow.put("Rows", pager.getResultList());
        maprow.put("Total", pager.getTotalCount());

        return maprow;
    }
}
